﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.IotInfo;
using LJX.SmartPark.Domain.IotInfo.LightPoles;
using LJX.SmartPark.Domain.Student;
using LJX.SmartPark.Service.IotInfo.LightPoles.Dto;
using LJX.SmartPark.Service.Repository;
using LJX.SmartPark.Service.StudentServices.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DB = LJX.SmartPark.Domain.IotInfo.LightPoles;

namespace LJX.SmartPark.Service.IotInfo.LightPoles
{
    public class LightPolesServeice : ILightPolesServeice
    {
        private readonly IRepository<DB.LightPoles> _lightpolesService;

        public LightPolesServeice(IRepository<DB.LightPoles> lightpolesService)
        {
            _lightpolesService = lightpolesService;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<Response<bool>> DeleteLightPolesAsync(DB.LightPoles input)
        {
            var result = await _lightpolesService.DeleteByIdAsync(input.MapTo<DB.LightPoles>());
            return Response<bool>.Ok(result > 0);
        }



        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Response<DB.LightPoles> GetLightPolesById(DB.LightPoles input)
        {
            var student = _lightpolesService.GetListQuery().FirstOrDefault(m => m.Id.ToString() == input.PoleNum);
            var result = student.MapTo<DB.LightPoles>();
            return Response<DB.LightPoles>.Ok(result);
        }

        /// <summary>
        /// 获取总条数
        /// </summary>
        /// <returns></returns>
        public int GetCount()
        {
            return _lightpolesService.GetCount();
        }

        /// <summary>
        /// 显示分页
        /// </summary>
        /// <param name="select"></param>
        /// <returns></returns>
        public async Task<Response<List<DB.LightPoles>>> GetLightPolesAsync(IotInfo.SelectRizhi select)
        {
            var students = await _lightpolesService.GetAllListAsync();
            var result = students.MapToList<DB.LightPoles>();

            var totalCount = result.Count();

            result = result.Skip(((select.pageIndex - 1) * select.pageSize)).Take(select.pageSize).ToList();

            return Response<List<DB.LightPoles>>.Ok(result, totalCount);
        }

        ///// <summary>
        ///// 查询
        ///// </summary>q
        ///// <param name="input"></param>
        ///// <returns></returns>
        //public async Task<Response<List<DB.LightPoles>>> GetLightPolesById(DB.LightPoles input)
        //{
        //    var student = _lightpolesService.GetListQuery().FirstOrDefault(m => m.Id.ToString() == input.PoleNum);
        //    var result = student.MapTo<DB.LightPoles>();
        //    return Response<List<DB.LightPoles>>.Ok(result);
        //}

        ///// <summary>
        ///// 显示
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //public async Task<Response<List<DB.LightPoles>>> GetLightPolesListAsync()
        //{
        //    var students = await _lightpolesService.GetAllListAsync();
        //    var result = students.MapToList<DB.LightPoles>();
        //    return Response<List<DB.LightPoles>>.Ok(result);
        //}

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<Response<bool>> PostAddLightPolesListAsync(DB.LightPoles input)
        {
            var result = _lightpolesService.InsertAsyncById(input.MapTo<DB.LightPoles>());

            return Response<bool>.Ok(result.Result > 0);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<Response<bool>> PutUpdLightPolesListAsync(DB.LightPoles input)
        {
            var result = _lightpolesService.UpdateAsync(input.MapTo<DB.LightPoles>());

            return Response<bool>.Ok(result.Result > 0);
        }

        /// <summary>
        /// 查询分页
        /// </summary>
        public class SelectRizhi
        {
            public int pageIndex { get; set; }
            public int pageSize { get; set; }
        }
    }
}
